<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@taglib prefix="supda" uri="http://www.supda.com/supda_tag" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="<%=basePath%>static/lib/html5.js"></script>
<script type="text/javascript" src="<%=basePath%>static/lib/respond.min.js"></script>
<script type="text/javascript" src="<%=basePath%>static/lib/PIE_IE678.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="<%=basePath%>static/static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="<%=basePath%>static/static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="<%=basePath%>static/lib/Hui-iconfont/1.0.7/iconfont.css" />
<link rel="stylesheet" type="text/css" href="<%=basePath%>static/lib/icheck/icheck.css" />
<link rel="stylesheet" type="text/css" href="<%=basePath%>static/static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="<%=basePath%>static/static/h-ui.admin/css/style.css" />
<!--[if IE 6]>
<script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>权限管理</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 系统管理 <span class="c-gray en">&gt;</span> 权限管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<div class="text-c">
		<form class="Huiform" method="post" action="" target="_self">
			<input type="text" class="input-text" style="width:250px" placeholder="权限名称" id="unknown" name="">
			<button type="button" class="btn btn-success" id="ext_search" name=""><i class="Hui-iconfont">&#xe665;</i> 搜权限节点</button>
		</form>
	</div>
	<div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l">
		<supda:permissionoperate buttonGroup="banner" menuId="${menuId}"/>
	</span> </div>
	<%--<table class="table table-border table-bordered table-bg">
		<thead>
			<tr>
				<th scope="col" colspan="7">权限节点</th>
			</tr>
			<tr class="text-c">
				<th width="25"><input type="checkbox" name="" value=""></th>
				<th width="40">ID</th>
				<th width="200">权限名称</th>
				<th>字段名</th>
				<th width="100">操作</th>
			</tr>
		</thead>
		<tbody>
			<tr class="text-c">
				<td><input type="checkbox" value="1" name=""></td>
				<td>1</td>
				<td>栏目添加</td>
				<td></td>
				<td><a title="编辑" href="javascript:;" onclick="admin_permission_edit('角色编辑','admin-permission-add.html','1','','310')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a> <a title="删除" href="javascript:;" onclick="admin_permission_del(this,'1')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a></td>
			</tr>
		</tbody>
	</table>
--%>
	<table id="tb" class="table table-border table-bordered table-hover table-bg table-sort">
	</table>	
</div>
<script type="text/javascript" src="<%=basePath%>static/lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="<%=basePath%>static/lib/layer/2.1/layer.js"></script> 
<script type="text/javascript" src="<%=basePath%>static/lib/laypage/1.2/laypage.js"></script> 
<script type="text/javascript" src="<%=basePath%>static/lib/My97DatePicker/WdatePicker.js"></script> 
<script type="text/javascript" src="<%=basePath%>static/lib/datatables/1.10.0/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="<%=basePath%>static/static/h-ui/js/H-ui.js"></script> 
<script type="text/javascript" src="<%=basePath%>static/static/h-ui.admin/js/H-ui.admin.js"></script> 
<script type="text/javascript">
var table; 
$(document).ready(function(){	
	table = $("#tb").dataTable({    
            "bProcessing": true, // 是否显示取数据时的那个等待提示  
            "ajax":"load",
            "orderClasses":false,
            "bDestroy":true,
            "bStateSave": true,//状态保存，使用了翻页或者改变了每页显示数据数量，会保存在cookie中，下回访问时会显示上一次关闭页面时的内容
            "bAutoWidth": true,//自动宽度          
            "bServerSide": true,//这个用来指明是通过服务端来取数据  
            "fnServerParams" : function (aoData) {
                aoData.push(
                    { "name": "fuzzysearch", "value": {"value":$("#unknown").val(), "datatype":["name"], "islike":true, "isand":false }},
                    { "name": "ext_search_valid","value":"1"}
                );
            },
            "sAjaxSource": "<%=basePath%>permission/search.shtml?now=" + new Date().getTime(),//这个是请求的地址  
            "fnServerData": retrieveData, // 获取数据的处理函数  
            "paging": true, 
            "searching":false,//隐藏搜索框
            "sPaginationType": "full_numbers",      //分页样式
            "bLengthChange": true, //改变每页显示数据数量  
            "bInfo": true,//页脚信息 
            "pageLength": 10,
         	 //当处理大数据时，延迟渲染数据，有效提高Datatables处理能力  
            "deferRender": true,
            "fnServerParams" : function (aoData) {
                aoData.push(
                    { "name": "ext_search_name", "value": $("#unknown").val() }
                );
            },
            "columns": [
						{ "data": "id",
						    "sTitle":"<input type='checkbox' name='' value=''>",
						    "sClass":"center",
						    "targets": 0,
						    "orderable": false,
						    "searchable": false, 
						    "render": function ( data, type, row,  meta ) {
						    		return "<input type='checkbox' value='"+data+"' name=''>";
						    }
						  },
                        { "data": "id",
                          "sTitle":"ID",
                          "sClass":"center"
                          
                        },
                        { "data": "name",
                        	"sTitle":"权限名",
                            "sClass":"center"
                        },
                        { "data": "icon",
                        	"sTitle":"icon",
                            "sClass":"center",
                            "render": function ( data, type, row,  meta ) {
					    		if(data!=null)
                            		return "<i class='Hui-iconfont'>"+data+"</i>";
                            	else
                            		return "";
                            }
                        },
                        { "data": "resUrl",
                        	"sTitle":"资源",
                            "sClass":"center"
                        },
                        { "data": "level",
                        	"sTitle":"级别",
                            "sClass":"center",
                            "render": function ( data, type, row,  meta ) {
					    		if(data=="0")
                            		return "一级菜单";
                            	else if(data == "1")
                            		return "二级菜单";
                            	else if(data == "2")
                            		return "按钮";
                            }
                        },
                        { "data": "buttonGroup",
                        	"sTitle":"页面区域",
                            "sClass":"center"
                        },
                        { "data": "description",
                        	"sTitle":"描述",
                            "sClass":"center"
                        },
                        {
                        	"data":"ishide",
                        	"sTitle":"锁定",
                        	"sClass":"center"
                        },
                       { "data": null,
                          "sTitle":"操作",
                          "sClass":"center",
						   "render": function ( data, type, row,  meta ) {
						           return $("#permission").html();
						  	}
                        },
                    ],
                    aoColumnDefs : [ 
                         { "aTargets" :　[8],
                            "sClass" : "center",
                         	"mRender" : function(data, type, full){ 
                         		if(full.ishide == "0"){
                         			return "<span class='label label-success radius'>已启用</span>";
                         		}else{
                         			return "<span class='label label-defaunt radius'>已停用</span>";
                         		}
                          	}
                          }],      
            "lengthMenu": [
                [10, 15, 20],
                [10, 15, 20] // 更改每页显示记录数
            ]

        });
		
		/*全选*/
		$("table thead tr th input:checkbox").on("click" , function(){
			$(this).closest("table").find("tr > td:first-child input:checkbox").prop("checked",$("table thead th input:checkbox").prop("checked"));
	    });
		
		$("#tb tbody").on( "click", "tr", function () {
			if ( $(this).hasClass("selected") ) {
				$(this).removeClass("selected");
			}
			else {
				table.$("tr.selected").removeClass("selected");
				$(this).addClass("selected");
			}		
		  } 
		);
		
		$("#ext_search").click(function(){
			ext_search();
		});
});
 
// 3个参数的名字可以随便命名,但必须是3个参数,少一个都不行  
function retrieveData(sSource,aoData, fnCallback) {  
    $.ajax({  
        url : sSource,//这个就是请求地址对应sAjaxSource  
        data : {"aoData":JSON.stringify(aoData)},//这个是把datatable的一些基本数据传给后台,比如起始位置,每页显示的行数  
        type : 'post',  
        dataType : 'json',  
        async : false,  
        success : function(result) {  
        	fnCallback(result);//把返回的数据传给这个方法就可以了,datatable会自动绑定数据的  
        },  
        error : function(msg) {  
        }  
    });  
}  

function ext_search()  
{  
	table.fnDraw();
}  

//无调整刷新当前页面数据
function refresh(){
	//$("#tb").dataTable().fnDraw(false);
	location.replace(location.href);
}


// 3个参数的名字可以随便命名,但必须是3个参数,少一个都不行  
function retrieveData(sSource,aoData, fnCallback) {  
    $.ajax({  
        url : sSource,//这个就是请求地址对应sAjaxSource  
        data : {"aoData":JSON.stringify(aoData)},//这个是把datatable的一些基本数据传给后台,比如起始位置,每页显示的行数  
        type : 'post',  
        dataType : 'json',  
        async : false,  
        success : function(result) {  
        	fnCallback(result);//把返回的数据传给这个方法就可以了,datatable会自动绑定数据的  
        },  
        error : function(msg) {  
        }  
    });  
}  
/*添加*/
function create(obj,url,w,h){
	var id = $(obj).parents('tr').find("input[type='checkbox']").val();
	layer_show("详情",url+"?id="+id,w,h);
}
/*查看*/
function show(obj,url,w,h){
	var id = $(obj).parents('tr').find("input[type='checkbox']").val();
	layer_show("详情",url+"?id="+id,w,h);
}


/*编辑*/
function edit(title,url,obj,w,h){
	var id = $(obj).parents('tr').find("input[type='checkbox']").val();
	layer_show(title,url+"?id="+id,w,h);
}

/*删除*/
function del(obj,turl){
	var id = $(obj).parents('tr').find("input[type='checkbox']").val();
	layer.confirm('确认要删除吗？',function(index){
		 $.ajax({  
		        url : turl,
		        data : {"id":id},
		        type : 'post',  
		        dataType : 'json',  
		        async : false,  
		        success : function(data) {
			        if (data=="success") {
				        $(obj).parents("tr").remove();
				    	layer.msg('已删除!',{icon:1,time:1000});
					}else if(data == "fail"){
						layer.msg('删除失败!',{icon:2,time:1000});
					}
			     },  
			    error : function(msg) {  
			        } 
		    });  
	});
	
}

/*停用*/
function locked(obj,turl){
	
	var id = $(obj).parents('tr').find("input[type='checkbox']").val();
	
	$.ajax({
			type : "post",
			dataType:"json",
			url:turl,
			data:{"id":id},
			success : function(data) {
				if (data=="unlocked") {
					$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已启用</span>');
					$(obj).attr("title","停用");
					$(obj).html("<i class='Hui-iconfont'>&#xe631;</i></a>")
					layer.msg('已启用!',{icon: 6,time:1000});
				} else if(data == "locked"){
					$(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已停用</span>');
					$(obj).html("<i class='Hui-iconfont'>&#xe6e1;</i></a>")
					$(obj).attr("title","启用");
					layer.msg('已停用!',{icon: 5,time:1000});
				}else if(data == "error"){
					layer.msg('错误!',{icon:1,time:1000});
				}
			}
		});
}
</script>
	<span style="display: none;" id="permission">
		<supda:permissionoperate buttonGroup="list" menuId="${menuId}"/>
	</span>
</body>
</html>
